const BaseIpcHandler = require('../BaseIpcHandler');

class GetRemoteListHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log(`>> GetRemoteListHandler params = `, params);

        // 业务逻辑
        let result = null;
        try {
            const rows = await this.app.remote_db.getRemoteList();
            result = { code: 0, msg: rows };
        } catch (err) {
            console.error('Get Remote List Failed, Error: ', err);
            result = { code: -1, msg: err.message };
        }

        // 返回结果
        // console.log(`GetRemoteListHandler result = `, result);
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = GetRemoteListHandler;
